import Http from "../http";

export async function categoryListApi() {
    return await Http.get<any[]>('dictionaryCategory')
}

export async function addCategoryApi(data:any) {
    return await Http.post('dictionaryCategory/add', data)
}

export async function editCategoryApi(id:number, data:any) {
    return await Http.put('dictionaryCategory/edit/' + id, data)
}

export async function deleteCategoryApi(id:number) {
    return await Http.delete('dictionaryCategory/delete/' + id)
}

export async function itemListApi(categoryId:number) {
    return await Http.get<any[]>('dictionaryItem?categoryId=' + categoryId)
}

export async function addItemApi(data:any) {
    return await Http.post('dictionaryItem/add', data)
}

export async function editItemApi(id:number, data:any) {
    return await Http.put('dictionaryItem/edit/' + id, data)
}


export async function deleteItemApi(id:number) {
    return await Http.delete('dictionaryItem/delete/' + id)
}

export async function queryDictionaryOfDeviceTypeApi(data:any={id : 0}) {
    const rows =  await Http.get<any[]>('dictionaryItem/DEVICE_TYPE/' + (data.id || 0))
    if(rows) {
        rows.forEach(row => {
            row.code = Number(row.code)
        })
    }
    return rows
}

export async function queryDictionaryOfChargeStrategyTypeApi() {
    const rows =  await Http.get<any[]>('dictionaryItem/CHARGE_STRATEGY/0')
    if(rows) {
        rows.forEach(row => {
            row.code = Number(row.code)
        })
    }
    return rows
}